package chapter2;

import java.util.Arrays;

public class FlagOfNetherlands {
    public static void swap(int[] arr,int x,int y){
        int tmp = arr[x];
        arr[x] = arr[y];
        arr[y] = tmp;
    }
    public static void flagOfNetherlands(int[] arr,int num){
        int left = -1;
        int right = arr.length;
        int pointer = 0;
        while (pointer < right){
            if (arr[pointer] < num){
                swap(arr,left+1,pointer);
                left++;
                pointer++;
            }else if (arr[pointer] == num){
                pointer++;
            }else{
                swap(arr,right-1,pointer);
                right--;
            }
        }
    }


    public static void main(String[] args) {
        int[] arr = {3,4,5,2,7,5,5,4,6};
        int num = 5;
        flagOfNetherlands(arr,num);
        System.out.println(Arrays.toString(arr));
    }
}
